Hệ thống quản lý ngân hàng bằng python
1 import pickle
2 import os
3 import pathlib
4 class Account :
5 accNo = 0
6 name = ''
7 deposit=0
8 type = ''
9
10 def createAccount(self):
11 self.accNo= int(input("Enter the account no : "))
12 self.name = input("Enter the account holder name : ")
13 self.type = input("Ente the type of account [C/S] : ")
14 self.deposit = int(input("Enter The Initial amount(>=500 for Saving and >=1000 for current"))
15 print("\n\n\nAccount Created")
16
17 def showAccount(self):
18 print("Account Number : ",self.accNo)
19 print("Account Holder Name : ", self.name)
20 print("Type of Account",self.type)
21 print("Balance : ",self.deposit)
22
23 def modifyAccount(self):
24 print("Account Number : ",self.accNo)
25 self.name = input("Modify Account Holder Name :")
26 self.type = input("Modify type of Account :")
27 self.deposit = int(input("Modify Balance :"))
28
29 def depositAmount(self,amount):
30 self.deposit += amount
31
32 def withdrawAmount(self,amount):
33 self.deposit -= amount
34
35 def report(self):
36 print(self.accNo, " ",self.name ," ",self.type," ", self.deposit)
37
38 def getAccountNo(self):
39 return self.accNo
40 def getAcccountHolderName(self):
41 return self.name
42 def getAccountType(self):
43 return self.type
44 def getDeposit(self):
45 return self.deposit
46
47
48 def intro():
49 print("\t\t\t\t**********************")
50 print("\t\t\t\tBANK MANAGEMENT SYSTEM")
51 print("\t\t\t\t**********************")
52
53 print("\t\t\t\tBrought To You By:")
54 print("\t\t\t\tprojectnotes.org")
55
56 input()
57
58
59
60 def writeAccount():
61 account = Account()
62 account.createAccount()
63 writeAccountsFile(account)
64
65 def displayAll():
66 file = pathlib.Path("accounts.data")
67 if file.exists ():
68 infile = open('accounts.data','rb')
69 mylist = pickle.load(infile)
70 for item in mylist :
71 print(item.accNo," ", item.name, " ",item.type, " ",item.deposit )
72 infile.close()
73 else :
74 print("No records to display")
75
76
77 def displaySp(num):
78 file = pathlib.Path("accounts.data")
79 if file.exists ():
80 infile = open('accounts.data','rb')
81 mylist = pickle.load(infile)
82 infile.close()
83 found = False
84 for item in mylist :
85 if item.accNo == num :
86 print("Your account Balance is = ",item.deposit)
87 found = True
88 else :
89 print("No records to Search")
90 if not found :
91 print("No existing record with this number")
92
93 def depositAndWithdraw(num1,num2):
94 file = pathlib.Path("accounts.data")
95 if file.exists ():
96 infile = open('accounts.data','rb')
97 mylist = pickle.load(infile)
98 infile.close()
99 os.remove('accounts.data')
100 for item in mylist :
101 if item.accNo == num1 :
102 if num2 == 1 :
103 amount = int(input("Enter the amount to deposit : "))
104 item.deposit += amount
105 print("Your account is updted")
106 elif num2 == 2 :
107 amount = int(input("Enter the amount to withdraw : "))
108 if amount <= item.deposit :
109 item.deposit -=amount
110 else :
111 print("You cannot withdraw larger amount")
112
113 else :
114 print("No records to Search")
115 outfile = open('newaccounts.data','wb')
116 pickle.dump(mylist, outfile)
117 outfile.close()
118 os.rename('newaccounts.data', 'accounts.data')
119
120
121 def deleteAccount(num):
122 file = pathlib.Path("accounts.data")
123 if file.exists ():
124 infile = open('accounts.data','rb')
125 oldlist = pickle.load(infile)
126 infile.close()
127 newlist = []
128 for item in oldlist :
129 if item.accNo != num :
130 newlist.append(item)
131 os.remove('accounts.data')
132 outfile = open('newaccounts.data','wb')
133 pickle.dump(newlist, outfile)
134 outfile.close()
135 os.rename('newaccounts.data', 'accounts.data')
136
137 def modifyAccount(num):
138 file = pathlib.Path("accounts.data")
139 if file.exists ():
140 infile = open('accounts.data','rb')
141 oldlist = pickle.load(infile)
142 infile.close()
143 os.remove('accounts.data')
144 for item in oldlist :
145 if item.accNo == num :
146 item.name = input("Enter the account holder name : ")
147 item.type = input("Enter the account Type : ")
148 item.deposit = int(input("Enter the Amount : "))
149
150 outfile = open('newaccounts.data','wb')
151 pickle.dump(oldlist, outfile)
152 outfile.close()
153 os.rename('newaccounts.data', 'accounts.data')
154
155
156 def writeAccountsFile(account) :
157
158 file = pathlib.Path("accounts.data")
159 if file.exists ():
160 infile = open('accounts.data','rb')
161 oldlist = pickle.load(infile)
162 oldlist.append(account)
163 infile.close()
164 os.remove('accounts.data')
165 else :
166 oldlist = [account]
167 outfile = open('newaccounts.data','wb')
168 pickle.dump(oldlist, outfile)
169 outfile.close()
170 os.rename('newaccounts.data', 'accounts.data')
171
172
173 # start of the program
174 ch=''
175 num=0
176 intro()
177
178 while ch != 8:
179 #system("cls");
180 print("\tMAIN MENU")
181 print("\t1. NEW ACCOUNT")
182 print("\t2. DEPOSIT AMOUNT")
183 print("\t3. WITHDRAW AMOUNT")
184 print("\t4. BALANCE ENQUIRY")
185 print("\t5. ALL ACCOUNT HOLDER LIST")
186 print("\t6. CLOSE AN ACCOUNT")
187 print("\t7. MODIFY AN ACCOUNT")
188 print("\t8. EXIT")
189 print("\tSelect Your Option (1-8) ")
190 ch = input()
191 #system("cls");
192
193 if ch == '1':
194 writeAccount()
195 elif ch =='2':
196 num = int(input("\tEnter The account No. : "))
197 depositAndWithdraw(num, 1)
198 elif ch == '3':
199 num = int(input("\tEnter The account No. : "))
200 depositAndWithdraw(num, 2)
201 elif ch == '4':
202 num = int(input("\tEnter The account No. : "))
203 displaySp(num)
204 elif ch == '5':
205 displayAll();
206 elif ch == '6':
207 num =int(input("\tEnter The account No. : "))
208 deleteAccount(num)
209 elif ch == '7':
210 num = int(input("\tEnter The account No. : "))
211 modifyAccount(num)
212 elif ch == '8':
213 print("\tThanks for using bank managemnt system")
214 break
215 else :
216 print("Invalid choice")
217
218 ch = input("Enter your choice : ")
219
220
221
222
223
224
225
226
227
228
229
230
231